
//
//  NewViewController.m
//  XWZ_News_Work
//
//  Created by penngshi on 16/1/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "NewViewController.h"
#import "NewListDetailViewController.h"
#import "NewCollectionViewCell.h"
#import "NewsModel.h"
#import "NewsArrModel.h"
#import "NewsDeatilWebViewController.h"
#import "photoesViewController.h"
#import "TodayViewController.h"
#import "adsModel.h"
@interface NewViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, NewCollectionCellDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) NSMutableArray *titleArr;
@property (nonatomic, strong) UIScrollView *scrollV;
@property (nonatomic, strong) UIView *viewD;
@property (nonatomic, strong) NSMutableArray *tempIdArr;
@property (nonatomic, strong) NSMutableArray *News0Arr;
@property (nonatomic, strong) NSMutableArray *News1Arr;
@property (nonatomic, strong) NSMutableArray *News2Arr;
@property (nonatomic, strong) NSMutableArray *News3Arr;
@property (nonatomic, strong) NSMutableArray *News4Arr;
@property (nonatomic, strong) NSMutableArray *News5Arr;
@property (nonatomic, strong) NSMutableArray *News6Arr;
@property (nonatomic, strong) NSMutableArray *News7Arr;
@property (nonatomic, strong) NSString *cid;
@property (nonatomic, assign) NSInteger page;

@end

@implementation NewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view, typically from a nib.
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.title = @"BestNews";
        self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:18], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil];
    [self.view addSubview:label];
    
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-24xiaoshi"] style:UIBarButtonItemStylePlain target:self action:@selector(rightAction)];
    [self getData];
    [self createView];
    
    
    
    
}
- (void)getData
{
    [self getData0];
    [self getData1];
    [self getData2];
    [self getData3];
    [self getData4];
    [self getData5];
    [self getData6];
    [self getData7];
}
- (void)getData0
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1348647909107/0-20.html"];
    //    NSLog(@"%@", urlStr);
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:@"T1348647909107"];
        self.News0Arr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            //            if (nil != model.ads) {
            //                NSMutableArray *adsArr = [NSMutableArray array];
            //                for (NSMutableArray *adsArr in [tempDic objectForKey:@"ads"]) {
            //                    for (NSMutableDictionary *adic in adsArr) {
            //                        NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adic];
            //                        [adsArr addObject:adsModel];
            //                    }
            //
            //                }
            //                model.ads = adsArr;
            //
            //            }
            
            
            [self.News0Arr addObject:model];
        }
        
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}
- (void)getData1
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1348648517839/0-20.html"];
    //    NSLog(@"%@", urlStr);
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:@"T1348648517839"];
        self.News1Arr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            //            if (nil != model.ads) {
            //                NSMutableArray *adsArr = [NSMutableArray array];
            //                for (NSMutableArray *adsArr in [tempDic objectForKey:@"ads"]) {
            //                    for (NSMutableDictionary *adic in adsArr) {
            //                        NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adic];
            //                        [adsArr addObject:adsModel];
            //                    }
            //
            //                }
            //                model.ads = adsArr;
            //
            //            }
            
            
            [self.News1Arr addObject:model];
        }
        
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}

- (void)getData2
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1348649079062/0-20.html"];
    //    NSLog(@"%@", urlStr);
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:@"T1348649079062"];
        self.News2Arr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            //            if (nil != model.ads) {
            //                NSMutableArray *adsArr = [NSMutableArray array];
            //                for (NSMutableArray *adsArr in [tempDic objectForKey:@"ads"]) {
            //                    for (NSMutableDictionary *adic in adsArr) {
            //                        NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adic];
            //                        [adsArr addObject:adsModel];
            //                    }
            //
            //                }
            //                model.ads = adsArr;
            //
            //            }
            
            
            [self.News2Arr addObject:model];
        }
        
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}

- (void)getData3
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1348649580692/0-20.html"];
    //    NSLog(@"%@", urlStr);
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:@"T1348649580692"];
        self.News3Arr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            //            if (nil != model.ads) {
            //                NSMutableArray *adsArr = [NSMutableArray array];
            //                for (NSMutableArray *adsArr in [tempDic objectForKey:@"ads"]) {
            //                    for (NSMutableDictionary *adic in adsArr) {
            //                        NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adic];
            //                        [adsArr addObject:adsModel];
            //                    }
            //
            //                }
            //                model.ads = adsArr;
            //
            //            }
            
            
            [self.News3Arr addObject:model];
        }
        
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}

- (void)getData4
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1350383429665/0-20.html"];
    //    NSLog(@"%@", urlStr);
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:@"T1350383429665"];
        self.News4Arr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            //            if (nil != model.ads) {
            //                NSMutableArray *adsArr = [NSMutableArray array];
            //                for (NSMutableArray *adsArr in [tempDic objectForKey:@"ads"]) {
            //                    for (NSMutableDictionary *adic in adsArr) {
            //                        NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adic];
            //                        [adsArr addObject:adsModel];
            //                    }
            //
            //                }
            //                model.ads = adsArr;
            //
            //            }
            
            
            [self.News4Arr addObject:model];
        }
        
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}

- (void)getData5
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1370583240249/0-20.html"];
    //    NSLog(@"%@", urlStr);
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:@"T1370583240249"];
        self.News5Arr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            //            if (nil != model.ads) {
            //                NSMutableArray *adsArr = [NSMutableArray array];
            //                for (NSMutableArray *adsArr in [tempDic objectForKey:@"ads"]) {
            //                    for (NSMutableDictionary *adic in adsArr) {
            //                        NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adic];
            //                        [adsArr addObject:adsModel];
            //                    }
            //
            //                }
            //                model.ads = adsArr;
            //
            //            }
            
            
            [self.News5Arr addObject:model];
        }
        
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}

- (void)getData6
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1348654204705/0-20.html"];
    //    NSLog(@"%@", urlStr);
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:@"T1348654204705"];
        self.News6Arr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            //            if (nil != model.ads) {
            //                NSMutableArray *adsArr = [NSMutableArray array];
            //                for (NSMutableArray *adsArr in [tempDic objectForKey:@"ads"]) {
            //                    for (NSMutableDictionary *adic in adsArr) {
            //                        NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adic];
            //                        [adsArr addObject:adsModel];
            //                    }
            //
            //                }
            //                model.ads = adsArr;
            //
            //            }
            
            
            [self.News6Arr addObject:model];
        }
        
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}

- (void)getData7
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1348650593803/0-20.html"];
    //    NSLog(@"%@", urlStr);
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:@"T1348650593803"];
        self.News7Arr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            //            if (nil != model.ads) {
            //                NSMutableArray *adsArr = [NSMutableArray array];
            //                for (NSMutableArray *adsArr in [tempDic objectForKey:@"ads"]) {
            //                    for (NSMutableDictionary *adic in adsArr) {
            //                        NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adic];
            //                        [adsArr addObject:adsModel];
            //                    }
            //
            //                }
            //                model.ads = adsArr;
            //
            //            }
            
            
            [self.News7Arr addObject:model];
        }
        
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}

- (void)getData0Up
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1348647909107/%ld-20.html", self.page];

    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:self.cid];
        NSMutableArray *newListArr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            if (nil != model.ads) {
                NSMutableArray *adsArr = [NSMutableArray array];
                for (NSMutableDictionary *adsDic in [tempDic objectForKey:@"ads"]) {
                    NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adsDic];
                    [adsArr addObject:adsModel];
                }
                model.ads = adsArr;
                
            }
            
        
            [newListArr addObject:model];
        }
        [self.News0Arr addObjectsFromArray:newListArr];
//        NSLog(@"^^^^^^%ld", self.NewsArr.count);
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}
- (void)getData1Up
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1348648517839/%ld-20.html", self.page];
    
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:self.cid];
        NSMutableArray *newListArr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            if (nil != model.ads) {
                NSMutableArray *adsArr = [NSMutableArray array];
                for (NSMutableDictionary *adsDic in [tempDic objectForKey:@"ads"]) {
                    NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adsDic];
                    [adsArr addObject:adsModel];
                }
                model.ads = adsArr;
                
            }
            
            
            [newListArr addObject:model];
        }
        [self.News1Arr addObjectsFromArray:newListArr];
        //        NSLog(@"^^^^^^%ld", self.NewsArr.count);
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}
- (void)getData2Up
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1348649079062/%ld-20.html", self.page];
    
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:self.cid];
        NSMutableArray *newListArr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            if (nil != model.ads) {
                NSMutableArray *adsArr = [NSMutableArray array];
                for (NSMutableDictionary *adsDic in [tempDic objectForKey:@"ads"]) {
                    NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adsDic];
                    [adsArr addObject:adsModel];
                }
                model.ads = adsArr;
                
            }
            
            
            [newListArr addObject:model];
        }
        [self.News0Arr addObjectsFromArray:newListArr];
        //        NSLog(@"^^^^^^%ld", self.NewsArr.count);
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}
- (void)getData3Up
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1348649580692/%ld-20.html", self.page];
    
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:self.cid];
        NSMutableArray *newListArr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            if (nil != model.ads) {
                NSMutableArray *adsArr = [NSMutableArray array];
                for (NSMutableDictionary *adsDic in [tempDic objectForKey:@"ads"]) {
                    NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adsDic];
                    [adsArr addObject:adsModel];
                }
                model.ads = adsArr;
                
            }
            
            
            [newListArr addObject:model];
        }
        [self.News3Arr addObjectsFromArray:newListArr];
        //        NSLog(@"^^^^^^%ld", self.NewsArr.count);
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}
- (void)getData4Up
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1350383429665/%ld-20.html", self.page];
    
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:self.cid];
        NSMutableArray *newListArr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            if (nil != model.ads) {
                NSMutableArray *adsArr = [NSMutableArray array];
                for (NSMutableDictionary *adsDic in [tempDic objectForKey:@"ads"]) {
                    NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adsDic];
                    [adsArr addObject:adsModel];
                }
                model.ads = adsArr;
                
            }
            
            
            [newListArr addObject:model];
        }
        [self.News4Arr addObjectsFromArray:newListArr];
        //        NSLog(@"^^^^^^%ld", self.NewsArr.count);
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}
- (void)getData6Up
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1348654204705/%ld-20.html", self.page];
    
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:self.cid];
        NSMutableArray *newListArr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            if (nil != model.ads) {
                NSMutableArray *adsArr = [NSMutableArray array];
                for (NSMutableDictionary *adsDic in [tempDic objectForKey:@"ads"]) {
                    NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adsDic];
                    [adsArr addObject:adsModel];
                }
                model.ads = adsArr;
                
            }
            
            
            [newListArr addObject:model];
        }
        [self.News6Arr addObjectsFromArray:newListArr];
        //        NSLog(@"^^^^^^%ld", self.NewsArr.count);
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}
- (void)getData5Up
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1370583240249/%ld-20.html", self.page];
    
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:self.cid];
        NSMutableArray *newListArr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            if (nil != model.ads) {
                NSMutableArray *adsArr = [NSMutableArray array];
                for (NSMutableDictionary *adsDic in [tempDic objectForKey:@"ads"]) {
                    NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adsDic];
                    [adsArr addObject:adsModel];
                }
                model.ads = adsArr;
                
            }
            
            
            [newListArr addObject:model];
        }
        [self.News5Arr addObjectsFromArray:newListArr];
        //        NSLog(@"^^^^^^%ld", self.NewsArr.count);
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}
- (void)getData7Up
{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/headline/T1348650593803/%ld-20.html", self.page];
    
    [xwzAFNetTool getNetWithURL:urlStr body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableArray *arr = [responseObject objectForKey:self.cid];
        NSMutableArray *newListArr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in arr) {
            NewsModel *model = [[NewsModel alloc] initWithDic:tempDic];
            if (nil != model.ads) {
                NSMutableArray *adsArr = [NSMutableArray array];
                for (NSMutableDictionary *adsDic in [tempDic objectForKey:@"ads"]) {
                    NewsArrModel *adsModel = [[NewsArrModel alloc] initWithDic:adsDic];
                    [adsArr addObject:adsModel];
                }
                model.ads = adsArr;
                
            }
            
            
            [newListArr addObject:model];
        }
        [self.News0Arr addObjectsFromArray:newListArr];
        //        NSLog(@"^^^^^^%ld", self.NewsArr.count);
        //        NSLog(@"%@", [[[self.NewsArr objectAtIndex:5] imgextra] objectAtIndex:0]);
        
        [self.collectionView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"新闻数据请求失败");
    }];
    
}


- (void)createView
{
//     self.tempIdArr = [NSMutableArray arrayWithObjects:@"T1348647909107", @"T1348648517839", @"T1348649079062", @"T1348649580692", @"T1350383429665", @"T1370583240249", @"T1348654204705", @"T1348650593803", nil];
//    
//    
//    self.cid = @"T1348647909107";
    self.page = 0;
    [self createTitleView];
    [self createCollectionView];
    
    
}
- (void)createTitleView
{
   
 
   self.titleArr = [NSMutableArray arrayWithObjects:@"头条", @"娱乐", @"体育", @"科技", @"轻松", @"原创", @"旅游", @"时尚", nil];
    
    self.scrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width , 40)];
    self.scrollV.contentSize = CGSizeMake((self.view.frame.size.width / 6) * self.titleArr.count + 20, 40);
    self.scrollV.showsHorizontalScrollIndicator = NO;
//    self.scrollV.backgroundColor = [UIColor greenColor];
    self.scrollV.bounces = NO;
    for (NSInteger i = 0; i < self.titleArr.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        button.frame = CGRectMake((self.view.frame.size.width / 6) * i, 0, self.view.frame.size.width / 6, 30);
        button.titleLabel.font = [UIFont systemFontOfSize:17.0];
        [button setTitle:[self.titleArr objectAtIndex:i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
        if (0 == i) {
            button.selected = YES;
            button.titleLabel.font = [UIFont systemFontOfSize:23.0];
        }
        
        button.tag = i + 1;
        [self.scrollV addSubview:button];
    }
    [self.view addSubview:self.scrollV];
    
    
//    self.viewD = [[UIView alloc] init];
//    self.viewD.backgroundColor = [UIColor redColor];
//    self.viewD.frame = CGRectMake(5, 55, (self.view.frame.size.width / 6) - 10, 2);
//    [self.scrollV addSubview:self.viewD];
    
    
    
    
//    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.button.frame = CGRectMake(scrollV.frame.size.width, scrollV.frame.origin.y, self.view.frame.size.width / 7 - 20, scrollV.frame.size.height);
//    [self.button setImage:[UIImage imageNamed:@"iconfont-xialaanniu"] forState:UIControlStateNormal];
//    [self.button addTarget:self action:@selector(buttonLIstAction:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:self.button];
    
    
}

- (void)createCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.itemSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 40, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.scrollEnabled = YES;
    self.collectionView.pagingEnabled = YES;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionView];
    [self.collectionView registerClass:[NewCollectionViewCell class] forCellWithReuseIdentifier:@"cell0"];
    [self.collectionView registerClass:[NewCollectionViewCell class] forCellWithReuseIdentifier:@"cell1"];
    [self.collectionView registerClass:[NewCollectionViewCell class] forCellWithReuseIdentifier:@"cell2"];
    [self.collectionView registerClass:[NewCollectionViewCell class] forCellWithReuseIdentifier:@"cell3"];
    [self.collectionView registerClass:[NewCollectionViewCell class] forCellWithReuseIdentifier:@"cell4"];
    [self.collectionView registerClass:[NewCollectionViewCell class] forCellWithReuseIdentifier:@"cell5"];
    [self.collectionView registerClass:[NewCollectionViewCell class] forCellWithReuseIdentifier:@"cell6"];
    [self.collectionView registerClass:[NewCollectionViewCell class] forCellWithReuseIdentifier:@"cell7"];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.titleArr.count;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (0 == indexPath.row) {
        NewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell0" forIndexPath:indexPath];
        cell.delegate = self;
        cell.page = indexPath.row;
        cell.arr = self.News0Arr;
        
        
        //    NSLog(@"^^%@", [self.tempIdArr objectAtIndex:indexPat.row]);
        
        return cell;

    }
    if (1 == indexPath.row) {
        NewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
        cell.delegate = self;
        cell.page = indexPath.row;
        cell.arr = self.News1Arr;
        
        
        //    NSLog(@"^^%@", [self.tempIdArr objectAtIndex:indexPat.row]);
        
        return cell;
        
    }
    if (2 == indexPath.row) {
        NewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell2" forIndexPath:indexPath];
        cell.delegate = self;
        cell.page = indexPath.row;
        cell.arr = self.News2Arr;
        
        
        //    NSLog(@"^^%@", [self.tempIdArr objectAtIndex:indexPat.row]);
        
        return cell;
        
    }
    if (3 == indexPath.row) {
        NewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell3" forIndexPath:indexPath];
        cell.delegate = self;
        cell.page = indexPath.row;
        cell.arr = self.News3Arr;
        
        
        //    NSLog(@"^^%@", [self.tempIdArr objectAtIndex:indexPat.row]);
        
        return cell;
        
    }
    if (4 == indexPath.row) {
        NewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell4" forIndexPath:indexPath];
        cell.delegate = self;
        cell.page = indexPath.row;
        cell.arr = self.News4Arr;
        
        
        //    NSLog(@"^^%@", [self.tempIdArr objectAtIndex:indexPat.row]);
        
        return cell;
        
    }
    if (5 == indexPath.row) {
        NewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell5" forIndexPath:indexPath];
        cell.delegate = self;
        cell.page = indexPath.row;
        cell.arr = self.News5Arr;
        
        
        //    NSLog(@"^^%@", [self.tempIdArr objectAtIndex:indexPat.row]);
        
        return cell;
        
    }
    if (6 == indexPath.row) {
        NewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell6" forIndexPath:indexPath];
        cell.delegate = self;
        cell.page = indexPath.row;
        cell.arr = self.News6Arr;
        
        
        //    NSLog(@"^^%@", [self.tempIdArr objectAtIndex:indexPat.row]);
        
        return cell;
        
    } else {
    
    
        NewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell7" forIndexPath:indexPath];
        cell.delegate = self;
        cell.page = indexPath.row;
        cell.arr = self.News7Arr;
        
        
        //    NSLog(@"^^%@", [self.tempIdArr objectAtIndex:indexPat.row]);
        
        return cell;
    
    }
    

    
    
    
}

// button 控制collectionview的偏移量
- (void)buttonAction:(UIButton *)sender
{
//    NSLog(@"关联");
    
    self.collectionView.contentOffset = CGPointMake(self.view.frame.size.width * (sender.tag - 1), 0);
    for (NSInteger i = 1; i < 11; i++) {
        UIButton *button = [self.scrollV viewWithTag:i];
        if (button.selected == YES) {
            button.selected = NO;
            button.titleLabel.font = [UIFont systemFontOfSize:17.0];
        }
        if (i == sender.tag) {
            sender.selected = YES;
            button.titleLabel.font = [UIFont systemFontOfSize:23.0];
            CGPoint point = CGPointMake(i * (self.view.frame.size.width / 6) - (self.scrollV.frame.size.width - (self.view.frame.size.width / 6)) / 2.0 - 35.0, 0);
            // 判断
            if (point.x < 0) {
                point.x = 0;
            } else if (point.x + self.scrollV.frame.size.width > self.scrollV.contentSize.width) {
                point.x = self.scrollV.contentSize.width - self.scrollV.frame.size.width;
            }
            // 偏移
            [self.scrollV setContentOffset:point animated:YES];
            
self.cid = [self.tempIdArr objectAtIndex:(i - 1)];
        }
    }
}

// collectionview控制button
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

    NSInteger page = self.collectionView.contentOffset.x / self.view.frame.size.width;
    for (NSInteger i = 1; i < 11; i++) {
        UIButton *button = [self.scrollV viewWithTag:i];
        if (button.selected == YES) {
            button.selected = NO;
             button.titleLabel.font = [UIFont systemFontOfSize:17.0];
        }
        
        if (i == self.collectionView.contentOffset.x / self.view.frame.size.width + 1) {
            button.selected = YES;
            button.titleLabel.font = [UIFont systemFontOfSize:23.0];
        }
    }
    
    
    CGPoint point = CGPointMake(page * (self.view.frame.size.width / 6) - (self.scrollV.frame.size.width - (self.view.frame.size.width / 6)) / 2.0 - 35.0, 0);
    // 判断
    if (point.x < 0) {
        point.x = 0;
    } else if (point.x + self.scrollV.frame.size.width > self.scrollV.contentSize.width) {
        point.x = self.scrollV.contentSize.width - self.scrollV.frame.size.width;
    }
    // 偏移
    [self.scrollV setContentOffset:point animated:YES];

    // 根据偏移量判断cid
    self.cid = [self.tempIdArr objectAtIndex:page];
    
    
}




- (void)buttonLIstAction:(UIButton *)sender
{
    if (sender == self.button) {
//        NewListDetailViewController *listVC = [[NewListDetailViewController alloc] init];
//        
//        [self.navigationController pushViewController:listVC animated:YES];
        NSLog(@"下拉");
    }
}

- (void)upToLadModeBypage:(NSInteger)page
{
    self.page += 20;
    switch (page) {
        case 0:
            [self getData0Up];
            break;
        case 1:
            [self getData1Up];
            break;
        case 2:
            [self getData2Up];
            break;
        case 3:
            [self getData3Up];
            break;
        case 4:
            [self getData4Up];
            break;
        case 5:
            [self getData5Up];
            break;
        case 6:
            [self getData6Up];
            break;
        default:
            break;
    }
    
}

- (void)pullToRefresh
{
    [self getData];
}

- (void)returnDetailByIndex:(NSInteger)index page:(NSInteger)page
{
    if (0 == page) {
        NewsModel *model = [self.News0Arr objectAtIndex:index];
        NewsDeatilWebViewController *deatilWebVC = [[NewsDeatilWebViewController alloc] init];
        
        if (![model.skipType isEqualToString:@"photoset"]) {
            deatilWebVC.docId = model.docid;
            [self.navigationController pushViewController:deatilWebVC animated:YES];
        } else {
            photoesViewController *photoVC = [[photoesViewController alloc] init];
            photoVC.photosetID = model.photosetID;
            [self.navigationController pushViewController:photoVC animated:YES];
            
            
        }
        
    }
    if (1 == page) {
        NewsModel *model = [self.News1Arr objectAtIndex:index];
        NewsDeatilWebViewController *deatilWebVC = [[NewsDeatilWebViewController alloc] init];
        
        if (![model.skipType isEqualToString:@"photoset"]) {
            deatilWebVC.docId = model.docid;
            [self.navigationController pushViewController:deatilWebVC animated:YES];
        } else {
            photoesViewController *photoVC = [[photoesViewController alloc] init];
            photoVC.photosetID = model.photosetID;
            [self.navigationController pushViewController:photoVC animated:YES];
            
            
        }
        
    }
    if (2 == page) {
        NewsModel *model = [self.News2Arr objectAtIndex:index];
        NewsDeatilWebViewController *deatilWebVC = [[NewsDeatilWebViewController alloc] init];
        
        if (![model.skipType isEqualToString:@"photoset"]) {
            deatilWebVC.docId = model.docid;
            [self.navigationController pushViewController:deatilWebVC animated:YES];
        } else {
            photoesViewController *photoVC = [[photoesViewController alloc] init];
            photoVC.photosetID = model.photosetID;
            [self.navigationController pushViewController:photoVC animated:YES];
            
            
        }
        
    }
    if (3 == page) {
        NewsModel *model = [self.News3Arr objectAtIndex:index];
        NewsDeatilWebViewController *deatilWebVC = [[NewsDeatilWebViewController alloc] init];
        
        if (![model.skipType isEqualToString:@"photoset"]) {
            deatilWebVC.docId = model.docid;
            [self.navigationController pushViewController:deatilWebVC animated:YES];
        } else {
            photoesViewController *photoVC = [[photoesViewController alloc] init];
            photoVC.photosetID = model.photosetID;
            [self.navigationController pushViewController:photoVC animated:YES];
            
            
        }
        
    }
    if (4 == page) {
        NewsModel *model = [self.News4Arr objectAtIndex:index];
        NewsDeatilWebViewController *deatilWebVC = [[NewsDeatilWebViewController alloc] init];
        
        if (![model.skipType isEqualToString:@"photoset"]) {
            deatilWebVC.docId = model.docid;
            [self.navigationController pushViewController:deatilWebVC animated:YES];
        } else {
            photoesViewController *photoVC = [[photoesViewController alloc] init];
            photoVC.photosetID = model.photosetID;
            [self.navigationController pushViewController:photoVC animated:YES];
            
            
        }
        
    }
    if (5 == page) {
        NewsModel *model = [self.News5Arr objectAtIndex:index];
        NewsDeatilWebViewController *deatilWebVC = [[NewsDeatilWebViewController alloc] init];
        
        if (![model.skipType isEqualToString:@"photoset"]) {
            deatilWebVC.docId = model.docid;
            [self.navigationController pushViewController:deatilWebVC animated:YES];
        } else {
            photoesViewController *photoVC = [[photoesViewController alloc] init];
            photoVC.photosetID = model.photosetID;
            [self.navigationController pushViewController:photoVC animated:YES];
            
            
        }
        
    }
    if (6 == page) {
        NewsModel *model = [self.News6Arr objectAtIndex:index];
        NewsDeatilWebViewController *deatilWebVC = [[NewsDeatilWebViewController alloc] init];
        
        if (![model.skipType isEqualToString:@"photoset"]) {
            deatilWebVC.docId = model.docid;
            [self.navigationController pushViewController:deatilWebVC animated:YES];
        } else {
            photoesViewController *photoVC = [[photoesViewController alloc] init];
            photoVC.photosetID = model.photosetID;
            [self.navigationController pushViewController:photoVC animated:YES];
            
            
        }
        
    }
    if (7 == page) {
        NewsModel *model = [self.News7Arr objectAtIndex:index];
        NewsDeatilWebViewController *deatilWebVC = [[NewsDeatilWebViewController alloc] init];
        
        if (![model.skipType isEqualToString:@"photoset"]) {
            deatilWebVC.docId = model.docid;
            [self.navigationController pushViewController:deatilWebVC animated:YES];
        } else {
            photoesViewController *photoVC = [[photoesViewController alloc] init];
            photoVC.photosetID = model.photosetID;
            [self.navigationController pushViewController:photoVC animated:YES];
            
            
        }
        
    }
}

- (void)rightAction
{
    TodayViewController *todayVC = [[TodayViewController alloc] init];
    [self.navigationController pushViewController:todayVC animated:YES];
}
// 轮播图点击
- (void)scrollViewToDetailByUrl:(NSString *)url
{
    photoesViewController *photoVC = [[photoesViewController alloc] init];
    photoVC.photosetID = url;
    [self.navigationController pushViewController:photoVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
